#include "Timer.h"
#include "PushButton.h"

/* CONSTRUCTOR */
PushButton::PushButton(PushButtonListener* pushButtonListener, int pushButtonPort)
{
  Timer* t = Timer::getTimer();
  m_pushButtonPort = pushButtonPort;
  m_pushButtonListener = pushButtonListener;
  pinMode(m_pushButtonPort, INPUT);
  
  t->every( 100, this);
}

/* METHODES */

/**
* \brief Verify if switch position has changed and update its state
* \param eventId
* \return none
*/
void PushButton::timerCallbackFunction(int eventId)
{
  boolean oldState = m_state;
  m_state = digitalRead(m_pushButtonPort);
  if (m_state == oldState)
  {
    /* state hasn't change, nothing to do */
  }
  else
  {
    m_pushButtonListener->pushButtonPositionChanged(m_state);
  }
}


